package cn.yunyichina.reservation.controller.console;

import java.util.Map;
import java.util.Properties;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.yunyichina.provider.framework.dubbo.service.ReservationService;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.reservation.component.qiniu.QiniuService;
import cn.yunyichina.reservation.constant.Console;
import cn.yunyichina.reservation.constant.HttpResponse;
import cn.yunyichina.reservation.controller.BaseResponseController;
import cn.yunyichina.reservation.util.RequestUtil;
import cn.yunyichina.utils.convert.JsonUtils;

/**
 *  后台管理：项目类型管理
 */
@RestController
@RequestMapping("console")
public class ConsoleItemTypeController extends BaseResponseController {

    private static final String RESERVATION_CONSOLE_ITEM_LIST = "yyt.reservation.itemtype.list";
    private static final String RESERVATION_CONSOLE_ITEM_GET = "yyt.reservation.itemtype.get";
    private static final String RESERVATION_CONSOLE_ITEM_ADD = "yyt.reservation.itemtype.add";
    private static final String RESERVATION_CONSOLE_ITEM_UPDATE = "yyt.reservation.itemtype.update";
    
    private static final String RESERVATION_CONSOLE_ITEM_DEL = "yyt.reservation.itemtype.del";
    
    @Resource
    private QiniuService qiniuService;

    @Resource
    private Properties yamlProperties;

    @GetMapping("itemTypes")
    public HttpResponse listItemType(HttpServletRequest request) {
        Map<String, String> param = RequestUtil.getAllParameters(request);
        Response response = ReservationService.callHumpFromInternal(
                RESERVATION_CONSOLE_ITEM_LIST, JsonUtils.toJsonString(param)
        );
        return toHttpResponse(response);
    }

    @GetMapping("itemType")
    public HttpResponse getItemType(HttpServletRequest request) {
        Map<String, String> param = RequestUtil.getAllParameters(request);
        Response response = ReservationService.callHumpFromInternal(
                RESERVATION_CONSOLE_ITEM_GET, JsonUtils.toJsonString(param)
        );
        return toHttpResponse(response);
    }

    @RequestMapping("addItemType")
    public HttpResponse addItemType(HttpServletRequest request) {
        Map<String, String> param = RequestUtil.getAllParameters(request);
        param.put("login_user", JsonUtils.toJsonString(this.getConsoleUser((String) request.getAttribute(Console.USERNAME))));
        Response response = ReservationService.callHumpFromInternal(
                RESERVATION_CONSOLE_ITEM_ADD, JsonUtils.toJsonString(param)
        );
        return toHttpResponse(response);
    }

    @RequestMapping("updateItemType")
    public HttpResponse updateItemType(HttpServletRequest request) {
        Map<String, String> param = RequestUtil.getAllParameters(request);
        param.put("login_user", JsonUtils.toJsonString(this.getConsoleUser((String) request.getAttribute(Console.USERNAME))));
        Response response = ReservationService.callHumpFromInternal(
                RESERVATION_CONSOLE_ITEM_UPDATE, JsonUtils.toJsonString(param)
        );
        return toHttpResponse(response);
    }
    
    @RequestMapping("delItemType")
    public HttpResponse delItemType(HttpServletRequest request) {
        Map<String, String> param = RequestUtil.getAllParameters(request);
        Response response = ReservationService.callHumpFromInternal(
        		RESERVATION_CONSOLE_ITEM_DEL, JsonUtils.toJsonString(param)
        );
        return toHttpResponse(response);
    }
    

}
